/**
 * This program is to exercise the change the feel and look of software
 */
package v1c08;

import java.awt.EventQueue;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.SwingUtilities;
import javax.swing.UIManager;

/**
 * @author gjunming@gmail.com
 * @version Aug 6, 2009 5:33:41 PM
 */
public class PlafTest {

	protected static final int FWIDTH = 400;
	protected static final int FHEIGHT = 300;

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		EventQueue.invokeLater(new Runnable() {

			@Override
			public void run() {
				PlafFrame plafFrame = new PlafFrame();
				plafFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
				plafFrame.setVisible(true);
				plafFrame.setTitle("Set Look And Feel");
				plafFrame.setSize(FWIDTH, FHEIGHT);

			}
		});

	}

}

class PlafFrame extends JFrame {

	private static final long serialVersionUID = 1L;
	private final JPanel plafPanel;

	public PlafFrame() {
		plafPanel = new JPanel();

		final UIManager.LookAndFeelInfo[] plafInfos = UIManager
				.getInstalledLookAndFeels();

		for (UIManager.LookAndFeelInfo plafInfo : plafInfos) {
			makeButton(plafInfo.getName(), plafInfo.getClassName());
		}
		add(plafPanel);
	}

	public void makeButton(String buttonText, final String lookName) {
		System.out.println(buttonText + lookName);
		JButton lookButton = new JButton(buttonText);
		plafPanel.add(lookButton);

		lookButton.addActionListener(new ActionListener() {

			@Override
			public void actionPerformed(ActionEvent event) {
				try {
					UIManager.setLookAndFeel(lookName);
					SwingUtilities.updateComponentTreeUI(PlafFrame.this);
				} catch (Exception e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}
			}
		});
	}
}
